﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = { 4,3,2,1,6,5,8,7 };
            Sum.Output(a);
            Console.WriteLine();
            Console.WriteLine("你要查找的数字2目前下标为:{0}", Sum.Search(2, a));
            a = Sum.Sort(a);
            Console.WriteLine();
            Sum.Output(a);
            Console.WriteLine();
            Console.WriteLine("你要查找的数字2目前下标为:{0}",Sum.Search(2,a));
            Console.ReadKey();
        }
    }
    
    class Sum
    {
        /// <summary>
        /// 打印输出
        /// </summary>
        /// <param name="values">打印数组</param>
        public static void Output(params int[] values)
        {
            foreach (var value in values)
            {
                Console.Write("{0}\t", value);
            }
        }
        public static int Search(int t,params int[] values)
        {
            int Index = 0;
            foreach (var value in values)
            {
                if (value == t)
                    return Index;
                Index++;
            }

            return Index;
        }
        /// <summary>
        /// 数组排序
        /// </summary>
        /// <param name="values">排序前数组</param>
        /// <returns>排序后的数组</returns>
        public static int[] Sort(params int[] values)
        {
            for (int j = 1; j < values.Length; j++)
            {
                for (int i = 0; i < values.Length - j; i++)
                { 
                    if (values[i] > values[i + 1])
                    { 
                        int temp = values[i];
                        values[i] = values[i + 1];
                        values[i + 1] = temp;
                    }
                }
            }
            return values;
        }
    }
}
